<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="酒店编码" prop="hotelCode">
      <el-input v-model="dataForm.hotelCode" placeholder="酒店编码"></el-input>
    </el-form-item>
    <el-form-item label="渠道酒店编码" prop="chanelHotelCode">
      <el-input v-model="dataForm.chanelHotelCode" placeholder="渠道酒店编码"></el-input>
    </el-form-item>
    <el-form-item label="酒店名称" prop="hotelName">
      <el-input v-model="dataForm.hotelName" placeholder="酒店名称"></el-input>
    </el-form-item>
    <el-form-item label="卖家酒店英文名称" prop="hotelNameEn">
      <el-input v-model="dataForm.hotelNameEn" placeholder="卖家酒店英文名称"></el-input>
    </el-form-item>
    <el-form-item label="酒店地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="酒店地址"></el-input>
    </el-form-item>
    <el-form-item label="" prop="country">
      <el-input v-model="dataForm.country" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="所属城市" prop="province">
      <el-input v-model="dataForm.province" placeholder="所属城市"></el-input>
    </el-form-item>
    <el-form-item label="" prop="district">
      <el-input v-model="dataForm.district" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="酒店所在城市" prop="city">
      <el-input v-model="dataForm.city" placeholder="酒店所在城市"></el-input>
    </el-form-item>
    <el-form-item label="酒店所在城市区县" prop="county">
      <el-input v-model="dataForm.county" placeholder="酒店所在城市区县"></el-input>
    </el-form-item>
    <el-form-item label="酒店所在商圈名" prop="area">
      <el-input v-model="dataForm.area" placeholder="酒店所在商圈名"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="酒店描述信息" prop="hotelInfo">
      <el-input v-model="dataForm.hotelInfo" placeholder="酒店描述信息"></el-input>
    </el-form-item>
    <el-form-item label="坐标类型G – GoogleB – 百度A – 高德M – 灵图" prop="axes">
      <el-input v-model="dataForm.axes" placeholder="坐标类型G – GoogleB – 百度A – 高德M – 灵图"></el-input>
    </el-form-item>
    <el-form-item label="经度" prop="axesX">
      <el-input v-model="dataForm.axesX" placeholder="经度"></el-input>
    </el-form-item>
    <el-form-item label="纬度" prop="axesY">
      <el-input v-model="dataForm.axesY" placeholder="纬度"></el-input>
    </el-form-item>
    <el-form-item label="星级" prop="starLevel">
      <el-input v-model="dataForm.starLevel" placeholder="星级"></el-input>
    </el-form-item>
    <el-form-item label="酒店类型
            商旅酒店、休闲度假（情侣、亲子）" prop="hotelType">
      <el-input v-model="dataForm.hotelType" placeholder="酒店类型
            商旅酒店、休闲度假（情侣、亲子）"></el-input>
    </el-form-item>
    <el-form-item label="酒店设施
            会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心" prop="hotelFacilities">
      <el-input v-model="dataForm.hotelFacilities" placeholder="酒店设施
            会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心"></el-input>
    </el-form-item>
    <el-form-item label="酒店服务
            运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务" prop="service">
      <el-input v-model="dataForm.service" placeholder="酒店服务
            运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务"></el-input>
    </el-form-item>
    <el-form-item label="起价
            单位：分" prop="sp">
      <el-input v-model="dataForm.sp" placeholder="起价
            单位：分"></el-input>
    </el-form-item>
    <el-form-item label="开业时间
            酒店填写的营业时间，无固定格式，如取值可以为“24小时”。" prop="openTime">
      <el-input v-model="dataForm.openTime" placeholder="开业时间
            酒店填写的营业时间，无固定格式，如取值可以为“24小时”。"></el-input>
    </el-form-item>
    <el-form-item label="装修时间" prop="decorateTime">
      <el-input v-model="dataForm.decorateTime" placeholder="装修时间"></el-input>
    </el-form-item>
    <el-form-item label="楼层信息" prop="floor">
      <el-input v-model="dataForm.floor" placeholder="楼层信息"></el-input>
    </el-form-item>
    <el-form-item label="是否国内酒店" prop="chinaHotel">
      <el-input v-model="dataForm.chinaHotel" placeholder="是否国内酒店"></el-input>
    </el-form-item>
    <el-form-item label="酒店营业状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="酒店营业状态"></el-input>
    </el-form-item>
    <el-form-item label="首图信息" prop="pictureurl">
      <el-input v-model="dataForm.pictureurl" placeholder="首图信息"></el-input>
    </el-form-item>
    <el-form-item label="品牌
            " prop="brand">
      <el-input v-model="dataForm.brand" placeholder="品牌
            "></el-input>
    </el-form-item>
    <el-form-item label="" prop="htgroup">
      <el-input v-model="dataForm.htgroup" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          hotelCode: '',
          chanelHotelCode: '',
          hotelName: '',
          hotelNameEn: '',
          address: '',
          country: '',
          province: '',
          district: '',
          city: '',
          county: '',
          area: '',
          phone: '',
          hotelInfo: '',
          axes: '',
          axesX: '',
          axesY: '',
          starLevel: '',
          hotelType: '',
          hotelFacilities: '',
          service: '',
          sp: '',
          openTime: '',
          decorateTime: '',
          floor: '',
          chinaHotel: '',
          status: '',
          pictureurl: '',
          brand: '',
          htgroup: ''
        },
        dataRule: {
          hotelCode: [
            { required: true, message: '酒店编码不能为空', trigger: 'blur' }
          ],
          chanelHotelCode: [
            { required: true, message: '渠道酒店编码不能为空', trigger: 'blur' }
          ],
          hotelName: [
            { required: true, message: '酒店名称不能为空', trigger: 'blur' }
          ],
          hotelNameEn: [
            { required: true, message: '卖家酒店英文名称不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '酒店地址不能为空', trigger: 'blur' }
          ],
          country: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '所属城市不能为空', trigger: 'blur' }
          ],
          district: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '酒店所在城市不能为空', trigger: 'blur' }
          ],
          county: [
            { required: true, message: '酒店所在城市区县不能为空', trigger: 'blur' }
          ],
          area: [
            { required: true, message: '酒店所在商圈名不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          hotelInfo: [
            { required: true, message: '酒店描述信息不能为空', trigger: 'blur' }
          ],
          axes: [
            { required: true, message: '坐标类型', trigger: 'blur' }
          ],
          axesX: [
            { required: true, message: '经度不能为空', trigger: 'blur' }
          ],
          axesY: [
            { required: true, message: '纬度不能为空', trigger: 'blur' }
          ],
          starLevel: [
            { required: true, message: '星级不能为空', trigger: 'blur' }
          ],
          hotelType: [
            { required: true, message: '酒店类型商旅酒店、休闲度假（情侣、亲子）不能为空', trigger: 'blur' }
          ],
          hotelFacilities: [
            { required: true, message: '酒店设施会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心不能为空', trigger: 'blur' }
          ],
          service: [
            { required: true, message: '酒店服务运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务不能为空', trigger: 'blur' }
          ],
          sp: [
            { required: true, message: '起价单位：分不能为空', trigger: 'blur' }
          ],
          openTime: [
            { required: true, message: '开业时间酒店填写的营业时间，无固定格式，如取值可以为“24小时”。不能为空', trigger: 'blur' }
          ],
          decorateTime: [
            { required: true, message: '装修时间不能为空', trigger: 'blur' }
          ],
          floor: [
            { required: true, message: '楼层信息不能为空', trigger: 'blur' }
          ],
          chinaHotel: [
            { required: true, message: '是否国内酒店不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '酒店营业状态不能为空', trigger: 'blur' }
          ],
          pictureurl: [
            { required: true, message: '首图信息不能为空', trigger: 'blur' }
          ],
          brand: [
            { required: true, message: '品牌不能为空', trigger: 'blur' }
          ],
          htgroup: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htchanelhotelinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.hotelCode = data.htChanelHotelinfo.hotelCode
                this.dataForm.chanelHotelCode = data.htChanelHotelinfo.chanelHotelCode
                this.dataForm.hotelName = data.htChanelHotelinfo.hotelName
                this.dataForm.hotelNameEn = data.htChanelHotelinfo.hotelNameEn
                this.dataForm.address = data.htChanelHotelinfo.address
                this.dataForm.country = data.htChanelHotelinfo.country
                this.dataForm.province = data.htChanelHotelinfo.province
                this.dataForm.district = data.htChanelHotelinfo.district
                this.dataForm.city = data.htChanelHotelinfo.city
                this.dataForm.county = data.htChanelHotelinfo.county
                this.dataForm.area = data.htChanelHotelinfo.area
                this.dataForm.phone = data.htChanelHotelinfo.phone
                this.dataForm.hotelInfo = data.htChanelHotelinfo.hotelInfo
                this.dataForm.axes = data.htChanelHotelinfo.axes
                this.dataForm.axesX = data.htChanelHotelinfo.axesX
                this.dataForm.axesY = data.htChanelHotelinfo.axesY
                this.dataForm.starLevel = data.htChanelHotelinfo.starLevel
                this.dataForm.hotelType = data.htChanelHotelinfo.hotelType
                this.dataForm.hotelFacilities = data.htChanelHotelinfo.hotelFacilities
                this.dataForm.service = data.htChanelHotelinfo.service
                this.dataForm.sp = data.htChanelHotelinfo.sp
                this.dataForm.openTime = data.htChanelHotelinfo.openTime
                this.dataForm.decorateTime = data.htChanelHotelinfo.decorateTime
                this.dataForm.floor = data.htChanelHotelinfo.floor
                this.dataForm.chinaHotel = data.htChanelHotelinfo.chinaHotel
                this.dataForm.status = data.htChanelHotelinfo.status
                this.dataForm.pictureurl = data.htChanelHotelinfo.pictureurl
                this.dataForm.brand = data.htChanelHotelinfo.brand
                this.dataForm.htgroup = data.htChanelHotelinfo.htgroup
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htchanelhotelinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'hotelCode': this.dataForm.hotelCode,
                'chanelHotelCode': this.dataForm.chanelHotelCode,
                'hotelName': this.dataForm.hotelName,
                'hotelNameEn': this.dataForm.hotelNameEn,
                'address': this.dataForm.address,
                'country': this.dataForm.country,
                'province': this.dataForm.province,
                'district': this.dataForm.district,
                'city': this.dataForm.city,
                'county': this.dataForm.county,
                'area': this.dataForm.area,
                'phone': this.dataForm.phone,
                'hotelInfo': this.dataForm.hotelInfo,
                'axes': this.dataForm.axes,
                'axesX': this.dataForm.axesX,
                'axesY': this.dataForm.axesY,
                'starLevel': this.dataForm.starLevel,
                'hotelType': this.dataForm.hotelType,
                'hotelFacilities': this.dataForm.hotelFacilities,
                'service': this.dataForm.service,
                'sp': this.dataForm.sp,
                'openTime': this.dataForm.openTime,
                'decorateTime': this.dataForm.decorateTime,
                'floor': this.dataForm.floor,
                'chinaHotel': this.dataForm.chinaHotel,
                'status': this.dataForm.status,
                'pictureurl': this.dataForm.pictureurl,
                'brand': this.dataForm.brand,
                'htgroup': this.dataForm.htgroup
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
